<template>
  <template v-if="isNotEmpty(dataList)" v-for="oneLevel in dataList">
    <el-sub-menu :index="genCurrentPath(oneLevel)" v-if="isNotEmpty(oneLevel.children)">
      <template #title>
        <el-icon>
          <location/>
        </el-icon>
        <span>{{ oneLevel.title }}</span>
      </template>
      <MenuItem :path="oneLevel.path" :data-list="oneLevel.children"></MenuItem>
    </el-sub-menu>
    <el-menu-item :index="genCurrentPath(oneLevel)" v-else>
      <template #title>
        <el-icon>
          <location/>
        </el-icon>
        <span>{{ oneLevel.title }}</span>
      </template>
    </el-menu-item>
  </template>
</template>
<script setup>
import {isNotEmpty} from "@/util/myUtil"
import {Location,} from "@element-plus/icons-vue";

/**
 * dataList需要满足以下数据结构
 * const menuClass = {
 *   title: {type: String, required: true,},
 *   path: {type: String, required: true,},
 *   children: {type: Array<menuClass>, required: false},
 * };
 */
defineProps({
  isRoot: {type: Boolean, default: false},
  path: {type: String, default: ""},
  dataList: {type: Array}
});
const genCurrentPath = function (routerData) {
  return this.path + "/" + routerData.path;
}
</script>